﻿using System;
using System.Web;
using System.Xml;
using SyCODE.Component;
using SyCODE.Component.DataFactory;
using System.Data.Common;
using System.Collections.Specialized;
using SyCODE.Component.Cryptography;
using SyCODE.Component.Security;

namespace SyCODE.Blog.Admin
{
    /// <summary>
    /// AdminUpdate.aspx 的处理程序
    /// </summary>
    public class AdminUpdate : HandlerBase
    {
        public override void ProcessRequest(HttpContext context)
        {
            NameValueCollection nvc = new NameValueCollection(context.Request.Form);
            bool flag = String.IsNullOrEmpty(nvc["account"]);

            if (this.Level > 0 || flag)             //是否超级管理员或正修改自己的密码
            {
                if (!String.IsNullOrEmpty(nvc["npwd"]))
                {
                    nvc.Set("npwd", SHA1.Encrypt(nvc["npwd"]));
                }

                if (flag)
                {
                    nvc.Add("account", this.Account);
                    nvc.Set("opwd", SHA1.Encrypt(nvc["opwd"]));
                }

                DBAM dbam = new DBAM();
                dbam.BuildParameters("adminupdate", nvc);
                try
                {
                    context.Response.Write(dbam.Execute());
                }
                finally
                {
                    dbam.Dispose();
                }
            }
            else
            {
                Function.ClientAlert(StringResource.GetField("powerfaild"));
            }
        }
    }
}
